package Visual;

import Entidades.Autos;
import Entidades.Marca;
import Entidades.Modelo;
import Negocio.DAOAutos;
import Negocio.DAOMarca;
import Negocio.DAOModelo;
import java.awt.*;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

public class FormAutos extends FormMenu {

    TableRowSorter<DefaultTableModel> sorter;
    DefaultTableModel model;
    DAOAutos h = new DAOAutos();

    public FormAutos() {
       initComponents();
        a.setVisible(false);
        this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        this.setMinimumSize(new Dimension(1360, 739));
        /*this.add(jTextField1);
        this.add(choice1);
        this.add(jTable1);
        this.add(jButton1);
        this.add(jButton2);
        this.add(jButton3);
        this.add(jButton4);
        jTextField1.setBounds(10, 10, 250, 35);
        choice1.setBounds(1000, 10, 250, 35);
        //jTable1.setBounds(100, 50, 1160, 450);
        jButton1.setBounds(100, 1200, 100, 50);
        jButton2.setBounds(180, 1200, 100, 50);
        jButton3.setBounds(260, 1200, 100, 50);
        jButton4.setBounds(340, 1200, 100, 50);*/
        choice1.add("Seleccione el filtro");
        choice1.add("NroUnidad");
        choice1.add("NroChasis");
        choice1.add("NroMotor");
        choice1.add("IDMarca");
        choice1.add("IDModelo");
        choice1.add("Año");
        choice1.add("IDColor");
        choice1.add("Fecha de ingresado");
        choice1.add("Cant pasajeros");
        choice1.add("ID Importador");
        choice1.add("Precio");
        choice1.add("Porcentaje Ganancia");
        choice1.add("Disponibilidad");
        choice1.add("KmsCompra");
        choice1.add("Cantidad de puertas");
        choice1.add("Cantidad de ruedas");
        choice1.add("Marca Ruedas");
        cargar();
        TableColumn miColumna = jTable1.getColumnModel().getColumn(3);
        JComboBox comboBox = new JComboBox(h.cargoIdmarca());
        miColumna.setCellEditor(new DefaultCellEditor(comboBox));
        TableColumn miColumna2 = jTable1.getColumnModel().getColumn(4);
        JComboBox comboBox2 = new JComboBox(h.cargoIdmodelo());
        miColumna2.setCellEditor(new DefaultCellEditor(comboBox2));
        TableColumn miColumna3 = jTable1.getColumnModel().getColumn(6);
        JComboBox comboBox3 = new JComboBox(h.cargoIdcolor());
        miColumna3.setCellEditor(new DefaultCellEditor(comboBox3));
        TableColumn miColumna4 = jTable1.getColumnModel().getColumn(9);
        JComboBox comboBox4 = new JComboBox(h.cargoIdimportador());
        miColumna4.setCellEditor(new DefaultCellEditor(comboBox4));
        TableColumn miColumna5 = jTable1.getColumnModel().getColumn(12);
        JComboBox comboBox5 = new JComboBox(h.cargobooleanas());
        miColumna5.setCellEditor(new DefaultCellEditor(comboBox5));
        TableColumn miColumna6 = jTable1.getColumnModel().getColumn(14);
        JComboBox comboBox6 = new JComboBox(h.cargobooleanas());
        miColumna6.setCellEditor(new DefaultCellEditor(comboBox6));
        TableColumn miColumna7 = jTable1.getColumnModel().getColumn(15);
        JComboBox comboBox7 = new JComboBox(h.cargobooleanas());
        miColumna7.setCellEditor(new DefaultCellEditor(comboBox7));
        TableColumn miColumna8 = jTable1.getColumnModel().getColumn(16);
        JComboBox comboBox8 = new JComboBox(h.cargobooleanas());
        miColumna8.setCellEditor(new DefaultCellEditor(comboBox8));
        TableColumn miColumna9 = jTable1.getColumnModel().getColumn(20);
        JComboBox comboBox9 = new JComboBox(h.cargobooleanas());
        miColumna9.setCellEditor(new DefaultCellEditor(comboBox9));
        jTable1.repaint();
        jTable1.setSize(1024, 768);
        sorter = new TableRowSorter<DefaultTableModel>(model);
        jTable1.setRowSorter(sorter);
        this.setTitle("Autos");



    }

    public void rf() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 0);
        sorter.setRowFilter(rf);
    }

    public void rf1() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 1);
        sorter.setRowFilter(rf);

    }

    public void rf2() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 2);
        sorter.setRowFilter(rf);

    }

    public void rf3() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 3);
        sorter.setRowFilter(rf);

    }

    public void rf4() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 4);
        sorter.setRowFilter(rf);

    }

    public void rf5() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 5);
        sorter.setRowFilter(rf);

    }

    public void rf6() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 6);
        sorter.setRowFilter(rf);

    }

    public void rf7() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 7);
        sorter.setRowFilter(rf);
    }

    public void rf8() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 8);
        sorter.setRowFilter(rf);

    }

    public void rf9() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 9);
        sorter.setRowFilter(rf);

    }

    public void rf10() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 10);
        sorter.setRowFilter(rf);

    }

    public void rf11() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 11);
        sorter.setRowFilter(rf);

    }

    public void rf12() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 12);
        sorter.setRowFilter(rf);

    }

    public void rf13() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 13);
        sorter.setRowFilter(rf);

    }

    public void rf14() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 17);
        sorter.setRowFilter(rf);

    }

    public void rf15() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 18);
        sorter.setRowFilter(rf);

    }

    public void rf16() {
        RowFilter<TableModel, Object> rf = null;
        rf = RowFilter.regexFilter(jTextField1.getText(), 19);
        sorter.setRowFilter(rf);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextField1 = new javax.swing.JTextField();
        choice1 = new java.awt.Choice();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField1KeyReleased(evt);
            }
        });

        jButton1.setText("Nuevo Registro");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Agregar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Modificar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Eliminar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(choice1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(choice1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(46, 46, 46)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addContainerGap(46, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        try{
            DefaultTableModel miTableModel = (DefaultTableModel) jTable1.getModel();
        int index = jTable1.getSelectedRow();
        Object val = jTable1.getValueAt(index, 0);
        String b = val.toString();
        int id = Integer.parseInt(b);
        miTableModel.removeRow(jTable1.getSelectedRow());
        if (h.EliminarAutos(id) == true) {
            JOptionPane.showMessageDialog(null, "¡Eliminado Correctamente!");
        }
    }catch(Exception ex){
            if(jTable1.getSelectedRow() == -1){
               JOptionPane.showMessageDialog(null, "Debe seleccionar la fila que desee.");
            }else{
                JOptionPane.showMessageDialog(null, "Error.");
            }
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jTextField1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyReleased
        switch (choice1.getSelectedIndex()) {
            case 1:
                rf();
                break;
            case 2:
                rf1();
                break;
            case 3:
                rf2();
                break;
            case 4:
                rf3();
                break;
            case 5:
                rf4();
                break;
            case 6:
                rf5();
                break;
            case 7:
                rf6();
                break;
            case 8:
                rf7();
                break;
            case 9:
                rf8();
                break;
            case 10:
                rf9();
                break;
            case 11:
                rf10();
                break;
            case 12:
                rf11();
                break;
            case 13:
                rf12();
                break;
            case 14:
                rf13();
                break;
            case 15:
                rf14();
                break;
            case 16:
                rf15();
                break;
            case 17:
                rf16();
                break;


        }
    }//GEN-LAST:event_jTextField1KeyReleased

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        DefaultTableModel miTableModel = (DefaultTableModel) jTable1.getModel();
        Object nuevaFila[] = {"", "", "", "", "", "", "", ""};
        miTableModel.addRow(nuevaFila);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        try{
        if (guardar() == true) {
            JOptionPane.showMessageDialog(null, "¡Agregado Correctamente!");
        }
        cargar();
        cargarcolumnas();
        }catch(Exception ex){
            if(jTable1.getSelectedRow() == -1){
               JOptionPane.showMessageDialog(null, "Debe seleccionar la fila que desee.");
            }else{
                JOptionPane.showMessageDialog(null, "Error. Revise los datos ingresados.");
            }
        }
    }//GEN-LAST:event_jButton2ActionPerformed
    void cargarcolumnas() {
        
        TableColumn miColumna = jTable1.getColumnModel().getColumn(3);
        JComboBox comboBox = new JComboBox(h.cargoIdmarca());
        miColumna.setCellEditor(new DefaultCellEditor(comboBox));
        TableColumn miColumna2 = jTable1.getColumnModel().getColumn(4);
        JComboBox comboBox2 = new JComboBox(h.cargoIdmodelo());
        miColumna2.setCellEditor(new DefaultCellEditor(comboBox2));
        TableColumn miColumna3 = jTable1.getColumnModel().getColumn(6);
        JComboBox comboBox3 = new JComboBox(h.cargoIdcolor());
        miColumna3.setCellEditor(new DefaultCellEditor(comboBox3));
        TableColumn miColumna4 = jTable1.getColumnModel().getColumn(9);
        JComboBox comboBox4 = new JComboBox(h.cargoIdimportador());
        miColumna4.setCellEditor(new DefaultCellEditor(comboBox4));
        TableColumn miColumna5 = jTable1.getColumnModel().getColumn(12);
        JComboBox comboBox5 = new JComboBox(h.cargobooleanas());
        miColumna5.setCellEditor(new DefaultCellEditor(comboBox5));
        TableColumn miColumna6 = jTable1.getColumnModel().getColumn(14);
        JComboBox comboBox6 = new JComboBox(h.cargobooleanas());
        miColumna6.setCellEditor(new DefaultCellEditor(comboBox6));
        TableColumn miColumna7 = jTable1.getColumnModel().getColumn(15);
        JComboBox comboBox7 = new JComboBox(h.cargobooleanas());
        miColumna7.setCellEditor(new DefaultCellEditor(comboBox7));
        TableColumn miColumna8 = jTable1.getColumnModel().getColumn(16);
        JComboBox comboBox8 = new JComboBox(h.cargobooleanas());
        miColumna8.setCellEditor(new DefaultCellEditor(comboBox8));
        TableColumn miColumna9 = jTable1.getColumnModel().getColumn(20);
        JComboBox comboBox9 = new JComboBox(h.cargobooleanas());
        miColumna9.setCellEditor(new DefaultCellEditor(comboBox9));
        jTable1.repaint();
    }
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        try {
            DefaultTableModel miTableModel = (DefaultTableModel) jTable1.getModel();
        int index = jTable1.getSelectedRow();
        Object val = jTable1.getValueAt(index, 0);
        String a = val.toString();
        int id = Integer.parseInt(a);
        Object val1 = jTable1.getValueAt(index, 1);
        String a1 = val1.toString();
        int NroChasis = Integer.parseInt(a1);
        Object val2 = jTable1.getValueAt(index, 2);
        String a2 = val2.toString();
        int NroMotor = Integer.parseInt(a2);
        Object val3 = jTable1.getValueAt(index, 3);
        String a3 = val3.toString();
        int IDMarca = Integer.parseInt(a3);
        Object val4 = jTable1.getValueAt(index, 4);
        String a4 = val4.toString();
        int IDModelo = Integer.parseInt(a4);
        String ano = (String) jTable1.getValueAt(index, 5);
        Object val6 = jTable1.getValueAt(index, 6);
        String a6 = val6.toString();
        int IDColor = Integer.parseInt(a6);
        String fechaing = (String) jTable1.getValueAt(index, 7);
        Object val8 = jTable1.getValueAt(index, 8);
        String a8 = val8.toString();
        int cantpasajeros = Integer.parseInt(a8);
        Object val9 = jTable1.getValueAt(index, 9);
        String a9 = val9.toString();
        int IDimportador = Integer.parseInt(a9);
        Object val10 = jTable1.getValueAt(index, 10);
        String a10 = val10.toString();
        int precio = Integer.parseInt(a10);
        Object val11 = jTable1.getValueAt(index, 11);
        String a11 = val11.toString();
        int porganancia = Integer.parseInt(a11);
        Object val12 = jTable1.getValueAt(index, 12);
        String a12 = val12.toString();
        boolean disp = booleanas(a12);
        Object val13 = jTable1.getValueAt(index, 13);
        String a13 = val13.toString();
        int kmsCompra = Integer.parseInt(a13);
        Object val14 = jTable1.getValueAt(index, 14);
        String a14 = val14.toString();
        boolean abs = booleanas(a14);
        Object val15 = jTable1.getValueAt(index, 15);
        String a15 = val15.toString();
        boolean airbagchofer =booleanas(a15);
        Object val16 = jTable1.getValueAt(index, 16);
        String a16 = val16.toString();
        boolean airbagacompanante = booleanas(a16);
        Object val17 = jTable1.getValueAt(index, 17);
        String a17 = val17.toString();
        int cantpuertas = Integer.parseInt(a17);
        Object val18 = jTable1.getValueAt(index, 18);
        String a18 = val18.toString();
        int cantruedas = Integer.parseInt(a18);
        String marcaruedas = (String) jTable1.getValueAt(index, 19);
        Object val20 = jTable1.getValueAt(index, 20);
        String a20 = val20.toString();
        boolean calefaccion = booleanas(a20);
        Autos nodo = new Autos();
        nodo.setNroUnidad(id);
        nodo.setNroChasis(NroChasis);
        nodo.setNroMotor(NroMotor);
        nodo.setIDMarca(IDMarca);
        nodo.setIDModelo(IDModelo);
        nodo.setAño(ano);
        nodo.setIDColor(IDColor);
        nodo.setFechaDeIngresado(fechaing);
        nodo.setCantidadPasajeros(cantpasajeros);
        nodo.setIDImportador(IDimportador);
        nodo.setPrecio(precio);
        nodo.setPorcentajeGanancia(porganancia);
        nodo.setDisponibilidad(disp);
        nodo.setKmsCompra(kmsCompra);
        nodo.setAbs(abs);
        nodo.setAirbagsChofer(airbagchofer);
        nodo.setAirbagsAcompañante(airbagacompanante);
        nodo.setCantPuertas(cantpuertas);
        nodo.setCantRuedas(cantruedas);
        nodo.setMarcaRuedas(marcaruedas);
        nodo.setCalefaccion(calefaccion);
        if (h.ModificarAutos(nodo) == true) {
            JOptionPane.showMessageDialog(null, "¡Modificado Correctamente!");
        }
        }catch(Exception ex){
            JOptionPane.showMessageDialog(null, "Error. Revise los datos ingresados.");
            if(jTable1.getSelectedRow() == -1){
               JOptionPane.showMessageDialog(null, "Debe seleccionar la fila que desee.");
            }
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormAutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormAutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormAutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormAutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormAutos().setVisible(true);
            }
        });
    }

    public boolean booleanas(String par) {
        if("Disponible".equals(par)){
            return true;
        }else{
            return false;
        }
    }

    public void cargar() {
        DAOAutos h = new DAOAutos();
        model = new DefaultTableModel();
        model = h.ModeloAutos();
        jTable1.setModel(model);

    }

    public boolean guardar() {
        DefaultTableModel miTableModel = (DefaultTableModel) jTable1.getModel();
        int index = jTable1.getSelectedRow();
        int id = 0;
        Object val1 = jTable1.getValueAt(index, 1);
        String a1 = val1.toString();
        int NroChasis = Integer.parseInt(a1);
        Object val2 = jTable1.getValueAt(index, 2);
        String a2 = val2.toString();
        int NroMotor = Integer.parseInt(a2);
        Object val3 = jTable1.getValueAt(index, 3);
        String a3 = val3.toString();
        int IDMarca = Integer.parseInt(a3);
        Object val4 = jTable1.getValueAt(index, 4);
        String a4 = val4.toString();
        int IDModelo = Integer.parseInt(a4);
        String ano = (String) jTable1.getValueAt(index, 5);
        Object val6 = jTable1.getValueAt(index, 6);
        String a6 = val6.toString();
        int IDColor = Integer.parseInt(a6);
        String fechaing = (String) jTable1.getValueAt(index, 7);
        Object val8 = jTable1.getValueAt(index, 8);
        String a8 = val8.toString();
        int cantpasajeros = Integer.parseInt(a8);
        Object val9 = jTable1.getValueAt(index, 9);
        String a9 = val9.toString();
        int IDimportador = Integer.parseInt(a9);
        Object val10 = jTable1.getValueAt(index, 10);
        String a10 = val10.toString();
        int precio = Integer.parseInt(a10);
        Object val11 = jTable1.getValueAt(index, 11);
        String a11 = val11.toString();
        int porganancia = Integer.parseInt(a11);
        Object val12 = jTable1.getValueAt(index, 12);
        String a12 = val12.toString();
        boolean disp = booleanas(a12);
        Object val13 = jTable1.getValueAt(index, 13);
        String a13 = val13.toString();
        int kmsCompra = Integer.parseInt(a13);
        Object val14 = jTable1.getValueAt(index, 14);
        String a14 = val14.toString();
        boolean abs = booleanas(a14);
        Object val15 = jTable1.getValueAt(index, 15);
        String a15 = val15.toString();
        boolean airbagchofer = booleanas(a15);
        Object val16 = jTable1.getValueAt(index, 16);
        String a16 = val16.toString();
        boolean airbagacompanante = booleanas(a16);
        Object val17 = jTable1.getValueAt(index, 17);
        String a17 = val17.toString();
        int cantpuertas = Integer.parseInt(a17);
        Object val18 = jTable1.getValueAt(index, 18);
        String a18 = val18.toString();
        int cantruedas = Integer.parseInt(a18);
        String marcaruedas = (String) jTable1.getValueAt(index, 19);
        Object val20 = jTable1.getValueAt(index, 20);
        String a20 = val20.toString();
        boolean calefaccion = booleanas(a20);
        Autos nodo = new Autos();
        nodo.setNroUnidad(id);
        nodo.setNroChasis(NroChasis);
        nodo.setNroMotor(NroMotor);
        nodo.setIDMarca(IDMarca);
        nodo.setIDModelo(IDModelo);
        nodo.setAño(ano);
        nodo.setIDColor(IDColor);
        nodo.setFechaDeIngresado(fechaing);
        nodo.setCantidadPasajeros(cantpasajeros);
        nodo.setIDImportador(IDimportador);
        nodo.setPrecio(precio);
        nodo.setPorcentajeGanancia(porganancia);
        nodo.setDisponibilidad(disp);
        nodo.setKmsCompra(kmsCompra);
        nodo.setAbs(abs);
        nodo.setAirbagsChofer(airbagchofer);
        nodo.setAirbagsAcompañante(airbagacompanante);
        nodo.setCantPuertas(cantpuertas);
        nodo.setCantRuedas(cantruedas);
        nodo.setMarcaRuedas(marcaruedas);
        nodo.setCalefaccion(calefaccion);
        return h.IngresarAutos(nodo);

    }
       
       
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private java.awt.Choice choice1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}
